package com.hbsx.oauth.util;

import com.zaxxer.hikari.util.DriverDataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;

import javax.sql.DataSource;
import java.sql.Driver;
import java.sql.SQLException;
import java.util.List;

public class JDBCTemplateTest {

    public static void main(String[] args) throws SQLException {
        Driver driver = new com.mysql.cj.jdbc.Driver();
        String url = "jdbc:mysql://localhost:3306/test";
        String username = "root";
        String password = "pass";
        String sql = "select * from user where user_name = 'dalaoyang'";
        DataSource dataSource = new SimpleDriverDataSource(driver,url,username,password);
        JdbcTemplate jdbcTemplate = new JdbcTemplate();
        jdbcTemplate.setDataSource(dataSource);
        List list = jdbcTemplate.queryForList(sql);
        System.out.println(list.get(0));
    }
}
